package spe.ui.properties;

import java.beans.PropertyChangeEvent;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;

public class MethodLibraryPropertySection extends PropertySection 
{
	private Label lbId;
	private Label lbName;
	private Text txtId;
	private Text txtName;
	
	private void initComponents(Composite comp)
	{
		lbId = getWidgetFactory().createLabel(comp, "Id");
		txtId = getWidgetFactory().createText(comp, "");
		lbName = getWidgetFactory().createLabel(comp, "Name");
		txtName = getWidgetFactory().createText(comp, "");
		
		FormData fd = new FormData();
		fd.top = new FormAttachment(0, 5);
		fd.left = new FormAttachment(0, 5);
		lbId.setLayoutData(fd);
		
		fd = new FormData();
		fd.top = new FormAttachment(0, 5);
		fd.left = new FormAttachment(lbId, 25);
		fd.right = new FormAttachment(100, -50);
		txtId.setLayoutData(fd);
		
		fd = new FormData();
		fd.top = new FormAttachment(lbId, 5);
		fd.left = new FormAttachment(lbId, 0, SWT.LEFT);
		lbName.setLayoutData(fd);
		
		fd = new FormData();
		fd.top = new FormAttachment(lbName, 0, SWT.TOP);
		fd.left = new FormAttachment(txtId, 0, SWT.LEFT);
		fd.right = new FormAttachment(txtId, 0, SWT.RIGHT);
		txtName.setLayoutData(fd);
	}
	
	@Override
	public void createControls(Composite parent, TabbedPropertySheetPage page)
	{
		super.createControls(parent, page);
		final Composite composite = getWidgetFactory().createFlatFormComposite(parent);
		
		initComponents(composite);
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent ev)
	{
		refresh();
	}
	
	@Override
	public void refresh()
	{
		if(element != null)
		{
			txtId.setText(element.getId());
			txtName.setText(element.getName());
		}
	}

	@Override
	protected void initControlsValues() 
	{
	}
}
